package com.zhixin.fans.ks.ui.dialog;

import android.content.Context;

import com.blankj.utilcode.util.ToastUtils;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.bean.SHARE_MEDIA;

import java.util.Map;

public abstract class AuthListener implements UMAuthListener {
    private Context mContext;
    private QMUITipDialog mTipDialog;

    public AuthListener(Context context) {
        mTipDialog = new QMUITipDialog.Builder(context)
                .setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING)
                .setTipWord("正在登录...")
                .create();
    }

    @Override
    public void onStart(SHARE_MEDIA share_media) {
        mTipDialog.show();

    }

    @Override
    public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
        mTipDialog.dismiss();
        onSuccess(share_media, i, map);
    }

    @Override
    public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
        throwable.printStackTrace();
        mTipDialog.dismiss();
        ToastUtils.showShort("登录错误：" + throwable.getMessage());
    }

    @Override
    public void onCancel(SHARE_MEDIA share_media, int i) {
        mTipDialog.dismiss();
        ToastUtils.showShort("用户取消登录");
    }


    public abstract void onSuccess(SHARE_MEDIA share_media, int code, Map<String, String> map);

}
